from Tkinter import *
from threading import Thread
import os, string, random, time, thread, threading
from guiGraph import *
from graph.node import *
import graph.graph
import graph.operations
import guiEdge
import tkMessageBox
import tkSimpleDialog
import tkFileDialog
import Tkinter as tk
import analyses.topology.properties
import Queue
from PIL import Image, ImageTk
from gams import *


#Globals
center_distance = 10.0
circle_diameter = 20
scaling_factor = 1.0 
c_width = 1000
c_height = 670
border = 20
colorMap = {1:"red", 2:"red", 3:"red", 4:"orange", 5:"orange", 6:"blue", 7:"blue", 8:"blue", 9:"black", 10:"black"}

class gui():
	root = None
	frame = None
	canvas = None
	done = 1
	mainMenu = None
	rightMenu = None
	fileMenu = None
	editMenu = None
	helpMenu = None
	graph = None
	idToNode = {}
	idToEdge = {}
	idToText = {}
	currentNode = None
	currentType = None
	canAddNode = False
	canMove = False
	metricLabels = {}
	weight_min = 1
	weight_max = 1
	gams = None


	def weight_normalize(self, x):
		try:
			y = 1 + (x-self.weight_min)*(10-1)/(self.weight_max-self.weight_min)
		except:
			print "in weight" , x
			print "weight_min" , self.weight_min
			print "weight_max" , self.weight_max
			y = 10

		return y

	def temp(self):
		print "hello"

	def quit(self):
		if tkMessageBox.askokcancel("Quit", "Do you really wish to quit?"):
			self.endproc()
			self.root.destroy()

	def run(self):
		'''self.makeCanvas()
		self.makeMenu()
		#self.makeWeights()'''
		self.refresh()
		pass

	def __init__(self,root, guiGraph, queue, threadClient ):
		#threading.Thread.__init__(self) 
		self.root = root
		self.threadClient = threadClient
		self.startSimulation = self.threadClient.startSimulation
		self.endproc = self.threadClient.endSimulation
		self.queue = queue
		self.graph = guiGraph
		self.xdim = 600
		self.ydim = 600
		self.root.protocol("WM_DELETE_WINDOW", self.quit)
		self.frame = Frame(self.root,width=1000,height=670)
		self.group = LabelFrame(self.root, text="Graph Metrics", padx=5, pady=5)
		self.group.pack(fill= X, side=LEFT)
		self.groupSimulation = LabelFrame(self.root, text="Simulation", padx=1, pady=5)
		self.groupSimulation.pack(fill= X, side=BOTTOM)
		self.simulationLabels = Label(self.groupSimulation, text=" No Schedule to simulate",  font=("Helvetica", 11),fg ='blue', justify=LEFT)
		self.simulationLabels.pack()
		imageFile = "greenMarker.png"
		self.aliveMarker = ImageTk.PhotoImage(Image.open(imageFile))
		self.image = self.aliveMarker
		self.gams = gams()


		self.makeCanvas()
		self.makeMenu()
		self.makeWeights()
		self.makeGraphMetrics()
		self.frame.pack()

	def makeWeights(self):
		list = []
		for e in self.graph.getEdges():
			list.append(e.weight)
		self.weight_max = max(list)
		self.weight_min = min(list)
		return 

	def makeCanvas(self):
		self.canvas = Canvas(self.frame, width=1000, height=670, relief=SUNKEN, bg="white", bd=2)
		self.text = Text()
		self.canvas.pack()
		self.canvas.bind("<Button-3>",self.do_popup)
		self.canvas.bind("<Button-1>",self.left_callback)
		self.canvas.bind("<B1-Motion>",self.drag_callback)
		self.canvas.bind("<ButtonRelease-1>", self.release_callback)
		#self.canvas.create_image(200, 200, image=self.image1)
		self.rightMenu = Menu(self.frame, tearoff=0)
		self.rightMenu.add_command(label="Remove",command=self.remove_node_callback)
		self.rightMenu.add_command(label="Add"  ,command=self.add_node_callback)
		self.rightMenu.add_command(label="Analyze"  ,command=self.analyze_node_callback)


	def makeMenu(self):
		self.mainMenu = Menu(self.root)
		self.root.config(menu=self.mainMenu)
		self.fileMenu = Menu(self.mainMenu, tearoff=0)
		self.fileMenu.add_cascade(label="New",command=self.temp)
		self.fileMenu.add_cascade(label="Open",command=self.temp)
		self.fileMenu.add_separator()
		self.fileMenu.add_command(label="Exit",command=self.quit)
		self.mainMenu.add_cascade(label="File",menu=self.fileMenu )
		self.editMenu = Menu(self.mainMenu, tearoff=0)
		self.editMenu.add_cascade(label="Node",command=self.temp)
		self.editMenu.add_cascade(label="Edge",command=self.temp)
		self.mainMenu.add_cascade(label="Edit",menu=self.editMenu )
		self.simulationMenu = Menu(self.mainMenu, tearoff =0)
		self.simulationMenu.add_command(label="Load Schedule",command=self.threadClient.setSchedFile)
		self.simulationMenu.add_separator()
		self.simulationMenu.add_command(label="Start",command=self.threadClient.startSimulation)
		self.simulationMenu.add_separator()
		self.simulationMenu.add_command(label="Pause",command=self.threadClient.pauseSimulation)
		self.simulationMenu.add_command(label="Resume",command=self.threadClient.resumeSimulation)
		self.mainMenu.add_cascade(label="Simulation",menu=self.simulationMenu )

	def makeGraphMetrics(self):
		results = analyses.topology.properties.computeProperties(self.graph)
		for res in results:
			arr = res.split(":")
			self.metricLabels[arr[0]] = Label(self.group, text=arr[1], justify=LEFT, font=("Helventica", 11), anchor=W)
			self.metricLabels[arr[0]].pack()
		self.done = 0 
		return


	def updateSimulationGroup(self, msg = None):
		if msg:
			self.simulationLabels.config(text= msg)
			self.simulationLabels.pack()
		return 
	
	def analyze_node_callback(self):
		results = analyses.topology.properties.computeProperties(self.graph)
		for res in results:
			arr = res.split(":")
			self.metricLabels[arr[0]].config(text= arr[1])
			self.metricLabels[arr[0]].pack()
		self.root.update()
		self.done = 0 
		return

	def refresh(self):
		results = analyses.topology.properties.computeProperties(self.graph)
		for res in results:
			arr = res.split(":")
			self.metricLabels[arr[0]].config(text= arr[1])
			self.metricLabels[arr[0]].pack()
		self.root.update()
		self.done = 0 
		return


	def remove_node_callback(self, silent=False):
		#if (self.currentType == "rectangle" and self.currentNode in self.idToNode.keys()):
		if (self.currentType == "image" and self.currentNode in self.idToNode.keys()):
			if silent or (tkMessageBox.askokcancel("Quit", "Do you really want to delet Node "+self.currentNode+"?")):
				self.canvas.delete(self.idToNode[(self.currentNode)])
				self.canvas.delete(self.idToText["text"+(self.currentNode)])
				node = self.graph.getNode(self.currentNode)
				node_id1 = None
				node_id2 = None
				if self.graph.directed:
					for neighbor_id in node.getNeighbourhood():
						node2 = self.graph.getNode(neighbor_id)
						node_id1 = str(node.name) + "-"+str(node2.name)
						node_id2 = str(node2.name) + "-"+str(node.name)
						if node_id1 in self.idToEdge.keys():
							self.canvas.delete(self.idToEdge[node_id1])
						if node_id2 in self.idToEdge.keys():
							self.canvas.delete(self.idToEdge[node_id2])
				else:
					for neighbor_id in node.getNeighbours():
						node2 = self.graph.getNode(neighbor_id)
						node_id1 = str(node.name) + "-"+str(node2.name)
						node_id2 = str(node2.name) + "-"+str(node.name)
						if node_id1 in self.idToEdge.keys():
							self.canvas.delete(self.idToEdge[node_id1])
						if node_id2 in self.idToEdge.keys():
							self.canvas.delete(self.idToEdge[node_id2])
 
				self.idToNode.pop(self.currentNode)
				self.idToText.pop("text"+self.currentNode)
				self.graph.removeNode(node) #All neighbour removed, edges removed, node removed. 
				self.graph.display()
		elif self.currentType == "line" and (self.currentNode) in self.idToEdge.keys():
			if silent or  (tkMessageBox.askokcancel("Quit", "Do you really want to delet Edge "+self.currentNode+"?")):
				self.graph.removeEdge(self.currentNode.replace("-"," "))
				self.canvas.delete(self.idToEdge[(self.currentNode)])
				self.idToEdge.pop(self.currentNode)
				if not self.graph.directed:
					arr = self.currentNode.split("-")
					self.graph.removeEdge(arr[1].strip() + " "+arr[0].strip())
					self.canvas.delete(self.idToEdge[( arr[1].strip() + "-"+arr[0].strip())])
					self.idToEdge.pop(arr[1].strip() + "-"+arr[0].strip())

		self.refresh()
		#self.root.update()
		

	def add_node_callback(self,silent=False,new_node_id="-1234"):
		#if self.canAddNode == True and self.currentType != "rectangle":
		if self.canAddNode == True and self.currentType != "image":
			if not silent: node_id = tkSimpleDialog.askstring("Node", "Enter the new node id :")
			else: 
				node_id = new_node_id

			node_id = node_id.strip()
			#print "adding node", node_id
			if node_id and not self.graph.getNode(node_id):
				self.graph.addNode(node_id)
				#self.printNodes()
				node = self.graph.getNode(node_id)
				node.coordinate_x = random.random() * center_distance - (center_distance/2) + 40
				node.coordinate_y = random.random() * center_distance - (center_distance/2) + 30
				idArr = self.drawNode(node_id,"0C0") 
				#print idArr
				node_widget_id = idArr[0]
				text_widget_id = idArr[1]
				if node_widget_id and text_widget_id:
					if not self.idToNode.has_key(node_id): self.idToNode[node_id] = node_widget_id
					if not self.idToText.has_key("text"+node_id): self.idToText["text"+node_id] =text_widget_id
			else:
				tkMessageBox.showwarning(title="Add Node", message ="Invalid Node id")

		elif self.canAddNode == True and self.currentType == "image":
			if not silent: node_id = tkSimpleDialog.askstring("Edge", "Enter node to connect:")
			else:
				node_id = new_node_id.strip()
			node_id = node_id.strip()
			if node_id and self.graph.getNode(node_id):
				node = self.graph.getNode(self.currentNode)
				node2 = self.graph.getNode(node_id)
				if node.name == node2.name:
					return
				
				self.graph.addEdge(node.name + " " + node2.name)
				line_widget_id2 = None
				if self.graph.directed:
					line_widget_id = self.drawEdge(node.name, node2.name,"black")
				else:
					line_widget_id = self.drawEdge(node.name, node2.name,"black")
					line_widget_id2 = self.drawEdge(node2.name, node.name,"black")

				#print "Creating an Edge ", line_widget_id , "   ", line_widget_id2
				if line_widget_id and line_widget_id not in self.idToEdge.keys():
					node_id = node.name +"-" + node2.name
					self.idToEdge[node_id] = line_widget_id
				if line_widget_id2 and line_widget_id2 not in self.idToEdge.keys():
					node_id = node2.name +"-" + node.name
					self.idToEdge[node_id] = line_widget_id2
		self.refresh()
		#self.root.update()

	def do_popup(self,event):
		try:
		        self.currentType = self.canvas.type(CURRENT)
			if self.canvas.type(CURRENT) == "image":
				self.rightMenu.tk_popup(event.x_root, event.y_root, 0)
				tags = self.canvas.itemcget(CURRENT,"tags")
				#print tags
				self.currentNode = (tags.split(" ")[0]).strip()
				self.canAddNode = True #TODO: make it true and handle edge addition
			elif self.canvas.type(CURRENT) == "line":
				#print "REached here"
				self.rightMenu.tk_popup(event.x_root, event.y_root, 0)
				tags = self.canvas.itemcget(CURRENT,"tags")
				#print tags
				self.currentNode = (tags.split(" ")[0]).strip()
				self.canAddNode = False
			else:
				self.rightMenu.tk_popup(event.x_root, event.y_root, 0)
				self.canAddNode = True
		finally:
			self.rightMenu.grab_release()


	def release_callback(self,event):
		self.root.config(cursor="")

	def drag_callback(self ,event):
		try:
			if self.canvas.type(CURRENT) == "image":
				self. root.config(cursor="fleur")
				tags = self.canvas.itemcget(CURRENT,"tags")
				self.currentNode = (tags.split(" ")[0]).strip()
				print "Dragging", self.currentNode 
				#dragging node
				tempNode = self.graph.getNode(self.currentNode)	
				#print tempNode.getNeighbours()
				if self.graph.directed: 
					for n in tempNode.getNeighbourhood():
						node_id = str(tempNode.name) + "-" + n
						if node_id not in self.idToEdge.keys():
							node_id = n + "-" + str(tempNode.name) 
							tempCoords  = self.canvas.coords(self.idToEdge[node_id])
							self.canvas.coords(self.idToEdge[node_id], tempCoords[0], \
									tempCoords[1], \
									tempCoords[2],tempCoords[3],
									event.x, \
									event.y)
						else:
							tempCoords  = self.canvas.coords(self.idToEdge[node_id])
							self.canvas.coords(self.idToEdge[node_id],event.x ,event.y, 
									tempCoords[2],tempCoords[3],
									tempCoords[4], \
									tempCoords[5])
				#else:
				for n in tempNode.getNeighbours():
					node_id1 = str(tempNode.name) + "-" + n
					node_id2 = n + "-" + str(tempNode.name)
					if node_id2 in self.idToEdge.keys():
						tempCoords  = self.canvas.coords(self.idToEdge[node_id2])
						self.canvas.coords(self.idToEdge[node_id2], tempCoords[0], \
								tempCoords[1], \
								tempCoords[2],tempCoords[3],
								event.x, \
								event.y)
					if node_id1 in self.idToEdge.keys():
						tempCoords  = self.canvas.coords(self.idToEdge[node_id1])
						self.canvas.coords(self.idToEdge[node_id1],event.x ,event.y, tempCoords[2],tempCoords[3], 
								tempCoords[4], \
								tempCoords[5])



				'''self.canvas.coords(CURRENT,event.x, event.y,\
						event.x + circle_diameter*scaling_factor, \
						event.y + circle_diameter*scaling_factor)'''

				self.canvas.coords(CURRENT,event.x, event.y-15)
				self.canvas.coords(self.idToText["text"+(self.currentNode)],event.x, event.y + 20 )
				tempNode.coordinate_x = event.x
				tempNode.coordinate_y = event.y

		finally:
			self.root.update()


	def left_callback(self,event):
		self.rightMenu.unpost()

	def right_callback(self,event):
		self.rightMenu.post(event.x,event.y)

	def drawGraph(self):
		self.SetRandomNodePosition()
		node_widget_id = None
		line_widget_id = None
		text_widget_id = None
		#draw all edges
		fill_color = "0C0"
		for node in self.graph.getNodes():
			x0 = ((node.coordinate_x*scaling_factor + (center_distance/2)) / center_distance * c_width) + border
			y0 = ((node.coordinate_y*scaling_factor + (center_distance/2)) / center_distance * c_height) + border
			(node_widget_id, text_widget_id) = self.drawNode(node.name,"0C0")			
			self.idToNode[node.name] = node_widget_id
			self.idToText["text"+str(node.name)] = text_widget_id
			for neighbor_id in node.getNeighbours():
				node2 = self.graph.getNode(neighbor_id)
				node_id = str(max(int(node.name),int(node2.name))) +"-" + str(min(int(node.name),int(node2.name)))
				line_widget_id2 = None
				if self.graph.directed:
					line_widget_id = self.drawEdge(node.name,node2.name,"black")
				else:
					line_widget_id = self.drawEdge(node.name,node2.name,"black")
					line_widget_id2 = self.drawEdge(node2.name,node.name,"black")
				if line_widget_id and line_widget_id not in self.idToEdge.keys():
					node_id = str(node.name) + "-"+str(node2.name)
					self.idToEdge[node_id] = line_widget_id

				if line_widget_id2 and line_widget_id2 not in self.idToEdge.keys():
					node_id = str(node2.name) + "-"+str(node.name)
					self.idToEdge[node_id] = line_widget_id2

		#self.refresh()
		#self.makeGraphMetrics()
		self.root.update()

        def SetRandomNodePosition(self):
		# sets random positions for all nodes
		for node in self.graph.getNodes():
			node.coordinate_x = random.randrange(0,500,1) #* center_distance - (center_distance/2)
			node.coordinate_y = random.randrange(0,370,1) #* center_distance - (center_distance/2)

	def drawNode(self,node_id,fill_color ):
		node_widget_id = None
		text_widget_id = None
		node = self.graph.getNode(node_id) 
		if not node:
			#print "FATAL ERROR id not found"
			return None
		x0 = node.coordinate_x
		y0 = node.coordinate_y

		if node.movable == 1:
			'''node_widget_id = self.canvas.create_rectangle(x0, y0,\
					x0 + circle_diameter*scaling_factor,\
					y0 + circle_diameter*scaling_factor,\
					fill="#" + fill_color, \
					tags = str(node.name))'''
			
			node_widget_id = self.canvas.create_image(x0, y0-10,image=self.aliveMarker , tags=str(node.name))
		else:
			'''node_widget_id = self.canvas.create_rectangle(x0, y0, \
					x0 + circle_diameter*scaling_factor, \
					y0 + circle_diameter*scaling_factor, \
					fill="#000",\
					tags = str(node.name))'''
			node_widget_id = self.canvas.create_image(x0, y0-15,image=self.aliveMarker, tags=str(node.name))

		#text_widget_id = self.canvas.create_text(x0, y0-15 '''+ circle_diameter*scaling_factor + 20''', \
		text_widget_id = self.canvas.create_text(x0, y0+25 , \
					anchor=tk.SW, text=str(node.name), \
					tags = "text"+str(node.name))
		return [node_widget_id,text_widget_id]

	def FindMidpoint(self,x1,y1,x2,y2):
		opp = float(abs(x1-x2))
		adj = float(abs(y1-y2))
		linelength = float(((opp)**2 + (adj)**2)**.5)
		hyp = float(linelength)
    		if adj == 0.0:
			new_opp = float(linelength/2)
			new_adj = 0.0
		elif opp == 0.0:
			new_adj = float(linelength/2)
			new_opp = 0.0
		else:
			tan_th = float(opp/adj)
			sine_th = float(opp/hyp)
			newlength = float(linelength/2)
			new_opp = float(sine_th * newlength)
			new_adj = float(new_opp/tan_th)
		direction = -1
		if (x2 > x1): direction = 1
		newx = x1 + direction * new_opp
		direction = -1
		if (y2 > y1): direction = 1
		newy = y1 + direction * new_adj
		return [newx, newy]

	def drawEdge(self,node1_id, node2_id,fill_color, edge_label="W"):
		line_widget_id = None
		node = self.graph.getNode(node1_id) 
		node2 = self.graph.getNode(node2_id) 
		if not node or not node2:
			return None
		x0 = node.coordinate_x
		y0 = node.coordinate_y
		points = [x0,y0]
		node_id = str(node.name) + "-" + str(node2.name)

		if node_id in self.idToEdge.keys():
			return
		if node and node2:
			x1 = node2.coordinate_x
			y1 = node2.coordinate_y
			midPoints = self.FindMidpoint(x0,y0,x1,y1)
			midPoints[0] += 10
			points += midPoints
			points += [x1,y1]
			#print len(points)
			line_widget_id = self.canvas.create_line(points, smooth = 'true' , fill = fill_color, arrow = LAST, tags = node_id, dash=(2,2))
		return line_widget_id

	def processIncoming(self):
		while self.queue.qsize():
			try:
				msg = self.queue.get(0)
				#print "Message from The Motheship!!! " , msg
				command = msg.split(" ")
				if command[0] == 'dn':
					#print "Trying to dropping node", command[1].strip()
					if self.graph.getNode(command[1].strip()):
						#print "Got the node too its tag is ", self.idToNode[command[1].strip()]
						self.currentType = "image" 
						self.currentNode = command[1].strip()
						self.remove_node_callback(True)
						self.updateSimulationGroup(" Dropping the Node "+ command[1])
					else:
						print "Node does not exist!" 
				elif command[0].strip() == 'de':
					#print "Trying to drop an edge", command[1].strip()
					if command[1].strip() in self.idToEdge.keys():
						#print "Got the Edge too its tag is ", self.idToEdge[command[1].strip()]
						self.currentType = "line" 
						self.currentNode = command[1].strip()
						self.remove_node_callback(True)
						self.updateSimulationGroup(" Dropping the Edge between "+ command[1])
						if not self.graph.directed:
							arr = command[1].strip("-")
							self.currentType = "line" 
							self.currentNode = arr[1].strip() +"-"+arr[0].strip()
							self.remove_node_callback(True)
						else:
							print "Edge does not exist!"
				elif command[0].strip() == 'an':
					#print "Trying to Add node"
					if not self.graph.getNode(command[1].strip()):
						#print "A new node"
						self.canAddNode = True
						self.currentType = "canvas"
						self.add_node_callback(True, command[1].strip())
						self.updateSimulationGroup(" Adding a new node "+ command[1])
					else:
						print "node already exisits"
				elif command[0].strip() == 'ae':
					print "trying to Add New Edge"
					arr =command[1].split("-")
					if self.graph.getNode(arr[0].strip()) and self.graph.getNode(arr[1].strip()):
						print "A new Edge"
						self.canAddNode  = True
						self.currentType = "image"
						self.currentNode = arr[0].strip()
						self.add_node_callback(True,arr[1].strip())
						self.updateSimulationGroup(" Adding a new Edge between"+ command[1])

				#elif command[0].strip() == 'q':
			except Queue.Empty:
				pass


class ThreadClient:
	def __init__(self, master):
		self.schedFile = "sched"
		self._simulationDoneEvent = threading.Event()
		self._simulationPaused = threading.Event()
		self._sleepTime = 100.0 
		self.master = master
		self.queue = Queue.Queue()
		ip = open('ip_5.txt', 'r')
		edgelist = ip.read().split("\n")
		ip.close()
		self.graphObj = guiGraph(False, True, edgelist)
		self.graphObj.create(edgelist)
		self.graphObj.display()
		self.gui = gui(master, self.graphObj, self.queue, self)
		self.gui.drawGraph()
		self.gui.simulationMenu.entryconfig(4, state=DISABLED)
		self.gui.simulationMenu.entryconfig(5, state=DISABLED)

	def togglePauseResumeMenu(self):
		if self.gui.simulationMenu.entrycget(4,"state")=="normal":
			self.gui.simulationMenu.entryconfig(4, state=DISABLED)
			self.gui.simulationMenu.entryconfig(5, state=NORMAL)
		else:
			self.gui.simulationMenu.entryconfig(4, state=NORMAL)
			self.gui.simulationMenu.entryconfig(5, state=DISABLED)


	def startSimulation(self):
		print "It starts!"
		if self.gui.simulationMenu.entrycget(2,"state")=="normal":
			self.gui.simulationMenu.entryconfig(2, state=DISABLED)
			self.gui.simulationMenu.entryconfig(0, state=DISABLED)
			self.gui.simulationMenu.entryconfig(4, state=NORMAL)
			self.gui.simulationMenu.entryconfig(5, state=DISABLED)

		self.gui.updateSimulationGroup(" Starting a schedule from file:" + self.schedFile +" ")
		self.running = 1
		self._simulationPaused.set()
		self.thread1 = threading.Thread(target=self.workerThread1)
		self.thread1.start()
		self.periodicCall()

	def periodicCall(self):
		self.gui.processIncoming()
		if not self.running and self.gui.simulationMenu.entrycget(2,"state")!="normal":
			self.gui.simulationMenu.entryconfig(2, state=NORMAL)
			self.gui.simulationMenu.entryconfig(0, state=NORMAL)
			self.gui.simulationMenu.entryconfig(4, state=DISABLED)
			self.gui.simulationMenu.entryconfig(5, state=DISABLED)
			self.gui.updateSimulationGroup(" Simualtion for the schedule completed ")
		self.master.after(100, self.periodicCall)
	
	def workerThread1(self):
		fp = open(self.schedFile)
		lines = fp.readlines()
		gui = self.gui
		for line in lines:
			arr = line.split(" ")
			time.sleep(int(arr[2]) * 0.3)
			msg = rand.random()
			self._simulationPaused.wait()
			self.queue.put( arr[0] + " " + arr[1])
		self.running = 0

	def endSimulation(self):
	        self.running = 0
		import sys
		sys.exit(1)

	def pauseSimulation(self):
		self.gui.updateSimulationGroup(" Simualtion Paused ")
		self._simulationPaused.clear()
		self.togglePauseResumeMenu()

	def resumeSimulation(self):
		self.gui.updateSimulationGroup(" Simualtion Resumed ")
		self._simulationPaused.set()
		self.togglePauseResumeMenu()
	
	def setSchedFile(self):
		#filename = (tkSimpleDialog.askstring("Simulator", "Enter The new Schedule:")).strip()
		filename = tkFileDialog.askopenfilename(parent=self.master,filetypes=[('Input Files','.in'),('All Files', '*.*')], \
				title='Select Schedule File')
		if filename:
			self.schedFile = filename.strip()
			self.gui.updateSimulationGroup(" New Schedule selected : " + filename.strip())

rand = random.Random()
root = Tk()
client = ThreadClient(root)
root.mainloop()

#

